{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-12-22T11:13:57.041161Z",
     "start_time": "2024-12-22T11:13:57.029155Z"
    }
   },
   "source": [
    "import os\n",
    "os.makedirs('./data', exist_ok=True)\n",
    "data_file = os.path.join('./data/house_tiny.csv')\n",
    "with open(data_file, 'w') as f:\n",
    "    f.write('NumRooms, Alley, Price\\n')\n",
    "    f.write('NA, Pave, 127500\\n')\n",
    "    f.write('2, NA, 106000\\n')\n",
    "    f.write('4, NA, 178100\\n')\n",
    "    f.write('NA, NA, 140000\\n')"
   ],
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-22T11:13:58.738966Z",
     "start_time": "2024-12-22T11:13:58.727993Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import pandas as pd\n",
    "\n",
    "data = pd.read_csv(data_file)\n",
    "print(data)"
   ],
   "id": "64c9ef82b1676fb7",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   NumRooms  Alley   Price\n",
      "0       NaN   Pave  127500\n",
      "1       2.0     NA  106000\n",
      "2       4.0     NA  178100\n",
      "3       NaN     NA  140000\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-22T11:20:21.977493Z",
     "start_time": "2024-12-22T11:20:21.965494Z"
    }
   },
   "cell_type": "code",
   "source": [
    "inputs1, inputs2, ouputs = data.iloc[:, 0], data.iloc[:, 1], data.iloc[:, 2]\n",
    "inputs1 = inputs1.fillna(inputs1.mean())\n",
    "print(inputs1)"
   ],
   "id": "531ab56d970069f2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    3.0\n",
      "1    2.0\n",
      "2    4.0\n",
      "3    3.0\n",
      "Name: NumRooms, dtype: float64\n"
     ]
    }
   ],
   "execution_count": 15
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-22T11:26:35.154864Z",
     "start_time": "2024-12-22T11:26:35.141352Z"
    }
   },
   "cell_type": "code",
   "source": [
    "inputs2 = pd.get_dummies(inputs2, dummy_na = True)\n",
    "print(inputs2)"
   ],
   "id": "4d679bc19c305cd5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      NA   Pave    NaN\n",
      "0  False   True  False\n",
      "1   True  False  False\n",
      "2   True  False  False\n",
      "3   True  False  False\n"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-12-22T11:26:41.763209Z",
     "start_time": "2024-12-22T11:26:41.750211Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import torch\n",
    "x, y, z = torch.tensor(inputs1.values), torch.tensor(inputs2.values), torch.tensor(ouputs.values)\n",
    "y = y[:, 0:2]\n",
    "x, y, z"
   ],
   "id": "78c9e794f1fb98c3",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(tensor([3., 2., 4., 3.], dtype=torch.float64),\n",
       " tensor([[False,  True],\n",
       "         [ True, False],\n",
       "         [ True, False],\n",
       "         [ True, False]]),\n",
       " tensor([127500, 106000, 178100, 140000]))"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "1d570e23c8f298c9"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
